<?php
namespace app\manage\model;
use think\Db;
use think\Model;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/5
 * Time: 16:25
 */
class ApartmentValue extends Model
{
    /**
     * 删除公寓设置的值
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function del($id){
        $where['sv_id'] = $id;
        $date['sv_state']=2;
        $data=$this
            ->where($where)
            ->update($date);
        return $data;
    }

    /**
     * 添加公寓设置的值
     * @param $data
     * @return int
     */
    public function add($data){
        $where['apartment_id'] = isset($data['apartment_id']) ? trim($data['apartment_id']) : "";
        $arr['tung_num'] = isset($data['tung_num']) ? trim($data['tung_num']) : "";
        $arr['create_id'] = create_id($data['token']);
      /*  $arr['property_fee'] = isset($data['property_fee']) ? json_encode(trim($data['property_fee'])) : "";
        $arr['net_fee'] = isset($data['net_fee']) ? json_encode(trim($data['net_fee'])) : "";
        $arr['gas_fee'] = isset($data['gas_fee']) ? json_encode(trim($data['gas_fee'])) : "";
        $arr['electricity_fees'] = isset($data['electricity_fees']) ? json_encode(trim($data['electricity_fees'])) : "";
      Meter Reading Time
        $arr['water'] = isset($data['water']) ? json_encode(trim($data['water'])) : "";
        $arr['date_time'] = isset($data['date_time']) ? trim($data['date_time']) : "";
      */
        $arr['inspection_time'] = isset($data['inspection_time']) ? trim($data['inspection_time']) : "";//抄表开始时间
        $arr['end_inspection'] = isset($data['end_inspection']) ? trim($data['end_inspection']) : "";//抄表结束时间
        $arr['settlement_time'] = isset($data['settlement_time']) ? trim($data['settlement_time']) : "";//结算时间
        $arr['date_time'] = isset($data['date_time']) ? trim($data['date_time']) : "";//结算日后几天计算

        $arr['unit_num'] = isset($data['unit_num']) ? trim($data['unit_num']) : "";
        $arr['housing_matching'] = isset($data['housing_matching']) ? trim($data['housing_matching']) : "";
        $arr['shop_matching'] = isset($data['shop_matching']) ? trim($data['shop_matching']) : "";
        $arr['shop_industry'] = isset($data['shop_industry']) ? trim($data['shop_industry']) : "";
        $arr['water'] = isset($data['water']) ? trim($data['water']) : "";
        $arr['electricity_fees'] = isset($data['electricity_fees']) ? trim($data['electricity_fees']) : "";
        $arr['gas_fee'] = isset($data['gas_fee']) ? trim($data['gas_fee']) : "";
        $arr['housing_oorientation'] = isset($data['housing_oorientation']) ? trim($data['housing_oorientation']) : "";
        $arr['net_fee'] = isset($data['net_fee']) ? trim($data['net_fee']) : "";
        $arr['property_fee'] = isset($data['property_fee']) ? trim($data['property_fee']) : "";
        $arr['add_time'] = time();
        if($where['apartment_id']==null){
            $data=Db::name('settings')
                ->insert($arr);
        }else{
            $data=Db::name('settings')
                ->where($where)
                ->update($arr);
        }
        return $data;
    }
}